package com.example.crowdfunding.mvc.config.enntity;

import com.example.crowdfunding.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

/**
 * 考虑到security的User只包含账号和密码，所以创建这个类用来扩充User包含的信息比如：邮箱
 */
public class SecurityAdmin extends User {

    private static final long serialVersionUID = 1L;
    // 这个admin包含所有原始信息
    private Admin originAdmin;

    /**
     * Instantiates a new Security admin.
     *
     * @param originAdmin the origin admin
     * @param authorities the authorities
     */
    public SecurityAdmin(
            // 传入原始的admin
            Admin originAdmin,
            // 权限和角色的集合
            List<GrantedAuthority> authorities
    ) {
        // 把数据传递给User
        super(originAdmin.getLoginAcct(), originAdmin.getUserPwd(), authorities);
        // 传过去之后擦除密码
        originAdmin.setUserPwd(null);
        // 把值传递给本类的admin,提供给get方法使用
        this.originAdmin = originAdmin;
    }

    public Admin getOriginAdmin() {

        return originAdmin;
    }

}
